package com.example.Sao.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.Sao.Data.DepartmentList;
import com.example.Sao.MyActivity.ReviseActivity;
import com.example.Sao.R;

import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;

/**
 * @ProjectName: scan
 * @Package: com.example.Sao.Adapter
 * @ClassName: PartmentAdpter
 * @Description: 部门列表适配器
 * @Author: 阿毛
 * @CreateDate: 2020/5/10 23:49
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/5/10 23:49
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class UseDepartmentAdpter extends RecyclerView.Adapter<UseDepartmentAdpter.mViewHolder>{
    private DepartmentList departmentList;
    private Context mContext;

    public UseDepartmentAdpter(DepartmentList departmentList, Context context){
        this.departmentList = departmentList;
        this.mContext = context;
    }

    public void setDepartmentList(DepartmentList departmentList) {
        this.departmentList = departmentList;
    }
    @Override
    public int getItemCount() {
        return departmentList.getDepartmentList().size();
    }

    @NonNull
    @Override
    public mViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.adpter_partment,viewGroup,false);
        return new mViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull mViewHolder mViewHolder, int i) {
                  mViewHolder.partment.setText(departmentList.getDepartmentList().get(i));
                  mViewHolder.mess.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          Intent intent =  new Intent(mContext, ReviseActivity.class);
                          intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
                          intent.putExtra("partment",departmentList.getDepartmentList().get(i));
                          mContext.startActivity(intent);
                      }
                  });
    }
    class mViewHolder extends RecyclerView.ViewHolder{
        private TextView partment;
        private RelativeLayout mess;
        public mViewHolder(View v){
            super(v);
            partment = v.findViewById(R.id.partment);
            mess  = v.findViewById(R.id.mess);
        }
    }
}
